// var host="http://127.0.0.1:9000";
var host="http://8.140.39.72:9000";
var dealerCode;
var username;
$(document).ready(function (){
	$("#button").click(function(){
		$.ajax({
		url:host+"/dealer/login",//请求的url(一般为后台接口)
		data:{username:$("#username").val(),
			  password:$("#password").val(),
		},//发送到服务器的参数
		type:"get",//请求方式为get或者post
		dataType:"json",//服务器响应的数据类型
		success:function(res){ //请求成功后返回的数据，赋值给变量'data'
		       //对data进行操作  
			   if(res['code']==0){
				   	console.log()
					var dealer=res['data'];
					dealerCode=dealer.dealerCode;
					username=dealer.username;
				   	location.href='index.html';
				   	window.sessionStorage.setItem('code',dealerCode);
					window.sessionStorage.setItem('username',username);
			   }
			   else{
				   	alert("账号或密码错误！");
			   }
			},error(){
					alert("系统繁忙")
			}
		});
	});

	//保存订单
	$("#saveOrder").click(function () {
		//出货仓库
		var selected=document.getElementById("selectA");
		var opt=selected.selectedIndex;
		var code=selected.options[opt].value;

		//产品编号
		var proCode=$("#pro_select").val();

		//配送方式
		var sendWay=document.getElementById("way").innerHTML;

		//起始日期
		var requireDateFrom=document.getElementById("test25").value;

		//截止日期
		var requireDateTo=document.getElementById("test1").value;

		//产品数量
		var proNum=$("#proNum").val();

		//经销商编码
		var dealerCode=window.sessionStorage.getItem("code");

		//备注
		var remark=$("#remark").val();
		$.ajax({
			url:host+"/stockOrder/saveOrder",
			type:"get",
			async:true,
			dataType:"json",
			data:{
				"dealerCode":dealerCode,
				"requireDateFrom":requireDateFrom,
				"requireDateTo":requireDateTo,
				"sendWay":sendWay,
				"storageOutCode":code,
				"storageInCode":"JY001",
				"proNum":proNum,
				"proCode":proCode,
				"remark":remark,
			},
			success:function (res) {
				console.log(res)
				if (res['message']=="保存成功"){
					alert("保存成功");
				}else {
					alert(res['data']);
				}
			},error:function (){
				alert("系统繁忙！")
			},
		})
	});
});


